package xg2013.totoro.web;

import java.util.Collection;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import xg2013.totoro.domain.GraduateProject;
import xg2013.totoro.domain.Student;
import xg2013.totoro.domain.Tutor;
import xg2013.totoro.domain.User;
import xg2013.totoro.service.DesignProjectService;
import xg2013.totoro.service.GetPresentUser;
import xg2013.totoro.service.StudentSelectProjectService;
import xg2013.totoro.service.StudentService;
import xg2013.totoro.service.TutorService;
import xg2013.totoro.service.UserService;


@Controller
@RequestMapping("/process")
public class TutorSelectStudentController {
	@Autowired
	private UserService userService;
	@Autowired
	private TutorService tutorService;
@Autowired
private DesignProjectService designProjectService;

	@Autowired
	private StudentSelectProjectService studentSelectProjectService;
	@Autowired
	private StudentService studentService;
	@RequestMapping("/selectStudents.html")
	public String selectStudents(Model model){
		User user = userService.get(GetPresentUser.presentUserId);
		Tutor tutor= tutorService.get(user.getId());
		Collection<GraduateProject> graduateProjectList = tutor.getGraduateProjects(); 
		model.addAttribute("graduateProjectList",graduateProjectList);
		model.addAttribute("T_id",tutor.getId());
		return "tutor/selectStudent";
		
	}
	public String select(Model model,Integer tutor_id,Integer student_id,Integer project_id  ){
		Tutor tutor=tutorService.get(tutor_id);
		GraduateProject graduateProject=designProjectService.get(project_id);
		Student student = studentService.get(student_id);
		student.setGraduateProject(graduateProject);
		studentService.update(student);
		return "tutor/selectStudent";
	}
}
